package com.ontheroad.mysql.leanCloud.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;

/**
 * AVOS服务拦截器
 * Created by kedong on 2017/11/11 0011.
 */
@Aspect
@Component
public class PushAop {

    @Autowired
    private MessageSource messageSource;

    @Pointcut("execution(* com.ontheroad.leanCloud.service.LeanCloudService.*(..))")
    public void pointCut() {
    }

    @Around("pointCut()")
    public Object around(ProceedingJoinPoint pjp) {
        System.out.println("调用推送服务之前...");
        Object result = null;
        try {
            String evn = messageSource.getMessage("TEST", null, "false", null);
            Boolean test = Boolean.valueOf(evn);
            if (!test) {
                // 测试环境就跳过
                result = pjp.proceed();
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
        System.out.println("调用推送服务之后...");
        return result;
    }

}
